package com.duolaibei.business.view.goods.mode;

import com.duolaibei.business.view.App;
import com.duolaibei.business.view.goods.greendao.DaoSession;
import com.duolaibei.business.view.goods.greendao.GoodsBeanDao;

import java.util.ArrayList;
import java.util.List;

public class GoodsBeanManager {
    private static GoodsBeanManager instance;
    GoodsBeanDao goodsBeanDao;
    DaoSession daoSession;

    private GoodsBeanManager() {
        goodsBeanDao = App.getApp().getDaoSession().getGoodsBeanDao();
        daoSession = App.getApp().getDaoSession();
    }

    public static GoodsBeanManager getInstance() {
        if (instance == null) {
            synchronized (GoodsBeanManager.class) {
                if (instance == null) {
                    instance = new GoodsBeanManager();
                }
            }
        }
        return instance;
    }

    //增加
    public void addGoods(GoodsBean testBean) {
        goodsBeanDao.insert(testBean);
    }

    //删除
    public void deleteGoods(GoodsBean testBean) {
        goodsBeanDao.delete(testBean);
    }

    //修改
    public void updateGoods(GoodsBean testBean) {
        goodsBeanDao.update(testBean);
    }

    //条件查询
    public List selectAllGoods() {
        goodsBeanDao.detachAll();//清除缓存
        List list1 = goodsBeanDao.queryBuilder().build().list();
        return list1 == null ? new ArrayList() : list1;
    }

    //删除表中内容
    public void deleteAllGoods() {
        goodsBeanDao.deleteAll();
    }
}
